<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <title>新鲜水果</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div class="search2-section">
    <div class="search2-wrapper bottom-border">
        <a href="javascript:history.go(-1)" class="return"></a>
        <div class="search2">
            <input id="keyword" type="text" name="" value="" placeholder="请输入关键字">
            <a onclick="searchPro(null)" href="javascript:;" class="search-btn">搜索</a>
        </div>
    </div>
    <div class="zhanwei"></div>
</div>
<!-- 搜索 -->

<div class="top-menu-section2">
    <div class="top-menu2 bottom-border">
        <a href="javascript:;" class="menu-item on">
            <span class="text">综合排序</span>
        </a>
        <a onclick="saleSort()" href="javascript:;" class="menu-item">
            <span class="text">销量</span>
        </a>
        <a onclick="priceSort()" href="javascript:;" class="menu-item">
            <span class="text">价格</span>
        </a>

    </div>
    <div class="zhanwei"></div>
</div>
<!-- 顶部菜单 -->

<div id="list" class="list2">

    <div class="list2-item bottom-border">
        <a href="details.html" class="text-img">
            <div class="img-wrapper">
                <img src="img/banner2.png" alt="" class="img">
                <img src="img/qiang-tag.png" alt="" class="tag">
            </div>
            <div class="text">
                <div class="text-top">
                    <div class="name">辽宁大连樱桃500g 8-12g/个 新鲜水果辽宁大连樱桃500g 8-12g/个 新鲜水果</div>
                    <div class="sell">销量9000</div>
                </div>
                <div class="old-price">市价¥32.00</div>
                <div class="now-price">会员价:￥<i>26.00</i></div>
            </div>
        </a>
        <div class="add-cart-wrapper">
            <div class="add-cart"></div>
        </div>
    </div>


    <!--  -->
    <!--<div class="list2-item bottom-border">-->
    <!--<a href="details.html" class="text-img">-->
    <!--<div class="img-wrapper">-->
    <!--<img src="img/banner2.png" alt="" class="img">-->
    <!--<img src="img/miao-tag.png" alt="" class="tag">-->
    <!--</div>-->
    <!--<div class="text">-->
    <!--<div class="text-top">-->
    <!--<div class="name">辽宁大连樱桃500g 8-12g/个 新鲜水果辽宁大连樱桃500g 8-12g/个 新鲜水果辽宁大连樱桃500g </div>-->
    <!--<div class="sell">销量9000</div>-->
    <!--</div>-->
    <!--<div class="old-price">市价¥32.00</div>-->
    <!--<div class="now-price">秒杀价:￥<i>26.00</i></div>-->
    <!--</div>-->
    <!--</a>-->
    <!--<div class="add-cart-wrapper">-->
    <!--<div class="add-cart"></div>-->
    <!--</div>-->
    <!--</div>-->
    <!--&lt;!&ndash;  &ndash;&gt;-->
    <!--<div class="list2-item bottom-border">-->
    <!--<a href="details.html" class="text-img">-->
    <!--<div class="img-wrapper">-->
    <!--<img src="img/banner2.png" alt="" class="img">-->
    <!--&lt;!&ndash; <img src="img/qiang-tag.png" alt="" class="tag"> &ndash;&gt;-->
    <!--</div>-->
    <!--<div class="text">-->
    <!--<div class="text-top">-->
    <!--<div class="name">辽宁大连樱桃500g 8-12g/</div>-->
    <!--<div class="sell">销量9000</div>-->
    <!--</div>-->
    <!--<div class="old-price">市价¥32.00</div>-->
    <!--<div class="now-price">会员价:￥<i>26.00</i></div>-->
    <!--</div>-->
    <!--</a>-->
    <!--<div class="add-cart-wrapper">-->
    <!--<div class="add-cart"></div>-->
    <!--</div>-->
    <!--</div>-->
    <!--  -->
</div>
<!-- 列表 -->

<!-- 以下为页面js部分 -->
<script type="text/javascript" src="js/rem.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/swiper.min.js"></script>
<script src="js/layers/layer.js" type="text/javascript" charset="utf-8"></script>
<script src="js/pages/public.js" type="text/javascript" charset="utf-8"></script>

<script>
    $('.top-menu2 .menu-item').click(function () {
        $(this).addClass('on').siblings().removeClass('on');
    })

    function addCart(productId) {
        $.ajax({
            type: "post",
            url: ajaxUrl + '/mobile/carItem/addProduct',
            async: true,
            //productId=412&memberId=623&normalId=508&num=1
            data: {'memberId': memberId, 'productId': productId, 'normalId': null, 'num': 1},
            success: function (data) {
                if (data.code == 0) {
                    alertMsg('成功加入购物车');
                } else {
                    alertMsg(data.message);
                }
                $('.spec-section').removeClass('on');
                $('.mask').hide();
                cartNum();
            },
            error: function () {
                errorTip();
            },
            complete: function () {

            }
        });
    }

    function priceSort() {
        searchPro(3)
    }
    function saleSort() {
        searchPro(2)
    }
    
    
    
    var sort = 1;
    searchPro(1);

    function searchPro(paixu) {
        if (paixu == null) {
            sort = 1
        } else {
            sort = paixu;
        }
        search();
    }

    function search() {

        var keyword = "";
        keyword = $("#keyword").val();

        $.ajax({
            type: "post",
            url: ajaxUrl + "/mobile/product/productList",
            async: true,
            data: {'memberId': memberId, 'page': 1, 'rows': 50, 'sort': sort, 'keyword': keyword},
            success: function (data) {
                var result = data.result;
                console.log(result);
                var str = '';
                for (var i = 0; i < result.length; i++) {
                    str += '<div class="list2-item bottom-border">' +
                        '        <a href="details.html?id=' + result[i].id + '" class="text-img">' +
                        '            <div class="img-wrapper">' +
                        '                <img src="' + result[i].image + '" alt="" class="img">' +
                        //   '                <img src="img/qiang-tag.png" alt="" class="tag">' +
                        '            </div>' +
                        '            <div class="text">' +
                        '                <div class="text-top">' +
                        '                    <div class="name">' + result[i].productName + '</div>' +
                        '                    <div class="sell">' + result[i].saleCount + '</div>' +
                        '                </div>' +
                        //     '                <div class="old-price">市价¥32.00</div>' +
                        '                <div class="now-price">会员价:￥<i>' + result[i].price + '</i></div>' +
                        '            </div>' +
                        '        </a>' +
                        '        <div class="add-cart-wrapper">' +
                        '            <div onclick="addCart(' + result[i].id + ')" class="add-cart"></div>' +
                        '        </div>' +
                        '    </div>';
                }
                //    alert(str)
                $('#list').html(str);
            }
        });
    }

    // 顶部导航
</script>
</body>
</html>